<template>
  <transition name="fade" :duration="300">
    <view v-if="loading.show" class="comp-loading">
      <image
        v-if="isIconPath"
        :src="loading.icon"
        :style="loading.style"
        alt="loading"
        class="comp-loading__img"
      />
      <view v-else-if="loading.icon === 'success'" class="comp-loading__icon">
        <icon type="success_no_circle" size="30" color="#ffffff"></icon>
      </view>
      <view v-else class="comp-loading__icon">
        <view class="comp-loading__icon-item"></view>
        <view class="comp-loading__icon-item"></view>
        <view class="comp-loading__icon-item"></view>
        <view class="comp-loading__icon-item"></view>
        <view class="comp-loading__icon-item"></view>
      </view>
      <view v-if="loading.text" class="comp-loading__text ellipsis">{{ loading.text }}</view>
    </view>
  </transition>
</template>

<script>
import { mapGetters } from 'vuex';

export default {
  props: {},

  computed: {
    ...mapGetters(['loading']),
    isIconPath() {
      return this.loading && this.loading.icon && this.loading.icon.indexOf('/') > -1;
    }
  }
};
</script>

<style lang="scss">
.comp-loading {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 200rpx;
  height: 200rpx;
  border-radius: 20rpx;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  flex-flow: column nowrap;
  justify-content: center;
  align-items: center;
  z-index: 999;

  &__img {
    width: 60rpx;
    height: 60rpx;
  }

  &__icon {
    width: auto;
    height: 60rpx;
    color: #fff;

    & > view {
      display: inline-block;
      vertical-align: middle;
      -webkit-animation: jump-animation 0.9s -0.5s infinite cubic-bezier(0.11, 0.49, 0.38, 0.78);
      animation: jump-animation 0.9s -0.5s infinite cubic-bezier(0.11, 0.49, 0.38, 0.78);
      width: 4rpx;
      height: 48rpx;
      background: #fff;
      margin-right: 8rpx;
    }

    & > view:nth-child(2),
    & > view:nth-child(4) {
      -webkit-animation-delay: -0.25s !important;
      animation-delay: -0.25s !important;
    }

    & > view:nth-child(1),
    & > view:nth-child(5) {
      -webkit-animation-delay: 0s !important;
      animation-delay: 0s !important;
    }

    & > view:last-child {
      margin-right: 0;
    }
  }

  &__text {
    color: #fff;
    font-size: 26rpx;
    margin-top: 20rpx;
    padding: 0 20rpx;
    text-align: center;
  }
}
</style>
